package leetcode_core.leetcode_2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class CombinationSum {

    private List<List<Integer>> ans = new ArrayList<>();

    public List<List<Integer>> combinationSum(int[] candidates, int target) {
        Arrays.sort(candidates);
        backtrack(candidates,target,new LinkedList<>(),0);
        return null;
    }

    private void backtrack(int[] nums,int target,LinkedList<Integer> track,int start){
        if(target == 0){
            ans.add(new ArrayList<>(track));
            return;
        }
        if(target < 0){
            return;
        }
        for(int i = start;i<nums.length;i++){
            //做选择
            track.add(nums[i]);
            //回溯递归
            backtrack(nums,target-nums[i],track,i);
            //撤销选择
            track.removeLast();
        }
    }

}
